<%@ page import="java.util.*,merlin.beans.*,merlin.dao.*,merlin.managers.*,merlin.servlets.*,merlin.utils.*" errorPage="mr_errhandler.jsp" %>

<HTML>
<HEAD>
    <TITLE>Industry Watch Free Trial Registration</TITLE>

	<!-- begin DWR imports -->
	<script type='text/javascript' src='dwr/interface/IndustryWatchManager.js'></script>
	<script type='text/javascript' src='dwr/engine.js'></script>
	<script type='text/javascript' src='dwr/util.js'></script>
	<!-- ends DWR imports -->

	<!-- begin Prototype import -->
	<script type='text/javascript' src='mr_scripts/prototype.js'></script>
	<!-- ends Prototype import -->

	<script>

		function isBlank(str){
			var len = str.length;
			if(len==0)return true;	// zero-length string
			for(i=0;i<len;i++){
				if(str.charAt(i) !=' ' && str.charAt(i) !='\n')return false; //some character is there
			}
			return true;
		}

		//validate the format of the e-mail address
		function isValidateEMailFormat(aEMailAddress){
			//Check for an email with a .com or .net extension
			var emailcom = /^[a-z][a-z_0-9\.]+@[a-z_0-9\.]+\.[a-z]{3}$/i
			//Check for an email with a .co.uk extension
			var emailcouk = /^[a-z][a-z0-9_\.]+@[a-z0-9_\.]+\.[a-z][a-z]\.[a-z][a-z]$/i
			var TheEMailAddress = new String(aEMailAddress);
			var tmpemail = aEMailAddress;
			var tmpamount = 0;
			var onechars = '';
			//validate the email format
			if ((TheEMailAddress.match(emailcom)) && (TheEMailAddress.match(emailcouk))) {
				return(false);
			};

			//ensure that the e-mail address contains 1 '@'
			for(var p=0; p < tmpemail.length; p++){
				onechars = tmpemail.charAt(p);
				if (onechars == '@')
					tmpamount = tmpamount + 1;
			}//for

			if (tmpamount != 1) {
				return(false);
			}

			return(true);
		}

		function submitForm(frm){
			// validate the fields first.
			if(isBlank(frm.txtFirstName.value)){
				alert("Firstname is required");
				frm.txtFirstName.focus();
				return;
			}
			if(isBlank(frm.txtSurname.value)){
				alert("Surname is required");
				frm.txtSurname.focus();
				return;
			}
			if(isBlank(frm.txtCompanyName.value)){
				alert("CompanyName is required");
				frm.txtCompanyName.focus();
				return;
			}
			if(isBlank(frm.txtEMailAddress.value)){
				alert("EMail Address is required");
				frm.txtEMailAddress.focus();
				return;
			}
			if(! isValidateEMailFormat(frm.txtEMailAddress.value)){
				alert("EMail Address is not a valid one");
				frm.txtEMailAddress.focus();
				return;
			}
			if(isBlank(frm.txtTelephone.value)){
				alert("Telephone number is required");
				frm.txtTelephone.focus();
				return;
			}

            // make remote DWR call.
            IndustryWatchManager.registerTrialUser(frm.txtFirstName.value,frm.txtSurname.value,frm.txtCompanyName.value,frm.txtEMailAddress.value,frm.txtTelephone.value,handleRegisterTrialUser);
		}

		function handleRegisterTrialUser(data){
			if(data == true){
				$("divContactDetails").hide();
				//$("divConfirmation").show();
				$("divLoggingIn").show();
				document.frmAutoLogin.txtEmailAddress.value = document.frmContactDetails.txtEMailAddress.value;
				document.frmAutoLogin.submit();
			}else{
				alert("Due to some errors your request could not be registered.\nPlease try again.");
			}
		}
	</script>
</HEAD>
<BODY>
	<jsp:include page = "iwHeaderSmallest.jsp"/>
	<br/>
	<div id="divContactDetails">
		<table align="center" width="750px" border="0">
			<tr>
				<td colspan="2" align="center" style='color:white;height:23px;font: 11px verdana,arial, sans-serif ;background:url("mr_images/LongBars-orange750.jpg") no-repeat;' >
					<h4 style="vertical-align:middle">&nbsp;Your Contact Details</h4>
				</td>
			</tr>
		</table>

		<table align="center" width="750px" cellpadding="0" cellspacing="0" style="font-family: Verdana, Helvetica, Arial, sans-serif;font-size: 11px;">
			<tbody>
			<tr>
				<td>
					<form name="frmContactDetails" method="post" action="merlin">

						<input type="hidden" name="mode" value="saveNewEnquiry">

						Please provide your contact details completing all fields of information.<br>
						<table style="margin: 14px 0px;font-family: Verdana, Helvetica, Arial, sans-serif;font-size: 11px;" cellpadding="5" cellspacing="0" >
							<tbody>
							<tr>
								<td style="vertical-align: middle; width: 110px;">
									<span style="color: rgb(177, 115, 12);">*</span> First Name
								</td>
								<td>
									<input name="txtFirstName" type="text" value=''>
								</td>
							</tr>
							<tr>
								<td style="vertical-align: middle;">
									<span style="color: rgb(177, 115, 12);">*</span> Surname
								</td>
								<td>
									<input name="txtSurname" type="text" value=''>
								</td>
							</tr>
							<tr>
								<td style="vertical-align: middle;">
									<span style="color: rgb(177, 115, 12);">*</span> Company
								</td>
								<td>
									<input name="txtCompanyName" type="text" value=''>
								</td>
							</tr>
							<tr>
								<td style="vertical-align: middle;">
									<span style="color: rgb(177, 115, 12);">*</span> Email Address
								</td>
								<td>
									<input name="txtEMailAddress" type="text"  value=''>
								</td>
							</tr>
							<tr>
								<td style="vertical-align: middle;">
									<span style="color: rgb(177, 115, 12);">*</span> Telephone No.
								</td>
								<td>
									<input name="txtTelephone" type="text" value=''>
								</td>
							</tr>
	  						</tbody>
						</table>
						<br>
						<input name="btnSend" class="input" value="Register" style="font-size: 11px; width: 130px;" onclick="submitForm(this.form)" type="button">
					</form>
					</div>
				</td>
	 		</tr>
			</tbody>
		</table>
	</div>

	<%--
	<div id="divConfirmation" style="display:none">
	    <p class="boldGreen">Thank your your request for a free trial of the Industry Watch Product.</p>
    	<p>We will be in touch with logon details shortly.</p>
		<p>&nbsp;</p>
    	<p><a href="http://www.industry-averages.co.uk">(Back to Home page)</a></p>
	</div>
	--%>

	<div align="center" id="divLoggingIn" style="color:black;background-color:#FFFF00;display:none;position:absolute;left:400px;top:350px">
		<%= request.getHeader("user-agent").indexOf("MSIE") != -1 ? "<BR>" : "" %>
		<h3 style="padding: 2px;font-family: Verdana, Helvetica, Arial, sans-serif;font-size: 15px;vertical-align:center">&nbsp; Logging in .... &nbsp;</h3>
	</div>

	<form name="frmAutoLogin" method="post" action="industryWatch">
		<input type="hidden" name="mode" value="loginForIndustryWatch">
		<input type="hidden" name ="txtPassword" value="password">
		<input type="hidden" name = "txtEmailAddress">
	</form>

	<jsp:include page="mr_footer.jsp"/>

	<!-- Start of StatCounter Code -->
<script type="text/javascript" language="javascript">
var sc_project=928985;
var sc_invisible=1;
var sc_partition=7;
var sc_security="206963a7";
</script>

<script type="text/javascript" language="javascript" src="http://www.statcounter.com/counter/frames.js"></script><noscript><a href="http://www.statcounter.com/" target="_blank"><img  src="http://c8.statcounter.com/counter.php?sc_project=928985&amp;amp;java=0&amp;amp;security=206963a7&amp;amp;invisible=1" alt="hidden hit counter" border="0"></a> </noscript>
<!-- End of StatCounter Code -->

</BODY>
</HTML>